package repository

import (
	"context"
	"gitee.com/jinmingzhi/cdce-service/internal/model"
	"gitee.com/jinmingzhi/kit/rdb"
)

const (
	batchTimeField  = "`id`, `batch_name`, `exam_time`, `status`"
	batchTimeOneSql = "select " + batchTimeField + " from `" + BATCHTIME + "` where `status` = ? limit 1"
)

type BatchTime interface {
	FindOne(ctx context.Context) (*model.BatchTime, error)
}

type BatchTimeImpl struct {
	repo rdb.Repository
}

func NewBatchTime(repo rdb.Repository) BatchTime {
	return &BatchTimeImpl{repo: repo}
}

func (c *BatchTimeImpl) FindOne(ctx context.Context) (*model.BatchTime, error) {
	data := &model.BatchTime{}
	err := c.repo.FindOne(ctx, data, batchTimeOneSql, true)
	if err != nil {
		return nil, err
	}
	return data, nil
}
